<?php
declare(strict_types=1);

namespace Service\HelperService;

class DateService
{
    /**
     * 计算时间戳之间的天数，不到一天算一天，整点算一天
     *
     * @param  int $start $end
     * @return string
     */
    public static function diffBetweenTwoDays($start,$end) {
        if ($start>$end) {
            $tmp = $start;
            $start = $end;
            $end = $tmp;
        }

        return floor(($end + 28800) / 86400) - floor(($start + 28800) / 86400) + 1;
    }
    
    
    public static function timesecond($start,$end)//将秒时间转换具体时间
    {
        
        $seconds = (int)($end-$start);
        $days_num="";
        if( $seconds>3600 ){
            if( $seconds>24*3600 ){
                $days        = (int)($seconds/86400);
                $days_num    = $days."天";
                $seconds    = $seconds%86400;//取余
            }
            $hours = intval($seconds/3600);
            $minutes = $seconds%3600;//取余下秒数
            $time = $days_num.$hours."时".gmstrftime('%M分钟%S秒', $minutes);
        }else{
            $time = gmstrftime('%H时%M分钟%S秒', $seconds);
        }
        return $time;
    }
}
